package com.tiantian.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.tiantian.dao.PlatformCapitalChangesRepository;
import com.tiantian.datajpa.service.impl.GenericServiceImpl;
import com.tiantian.domain.Platformcapitalchanges;
import com.tiantian.service.PlatformCapitalChangesService;

@Service
@Transactional
public class PlatformCapitalChangesServiceImpl extends GenericServiceImpl<Platformcapitalchanges, Integer> implements PlatformCapitalChangesService {
	private PlatformCapitalChangesRepository repository;

	@Autowired
	public void setRepository(PlatformCapitalChangesRepository repository) {
		super.setGenericDAO(repository);
		this.repository = repository;
	}

	public String getChangeNo(String changeDate) {
		StringBuilder sql = new StringBuilder();
		Map<String, Object> params = new HashMap<String, Object>();

		sql.append("select max(ChangeNo) ChangeNo from Platformcapitalchanges a");
		sql.append("  where 1=1 ");
		if (StringUtils.isNotBlank(changeDate)) {
			sql.append(" and DATE_FORMAT(changedate,'%Y-%m-%d')=:changedate ");
			params.put("changedate", changeDate);
		}
		List<Map<String, Object>> ret = repository.queryHumpListMapBySql(sql.toString(), params);
		if (ret != null && ret.size() > 0) {
			if (ret.get(0).get("changeno") != null) {
				return ret.get(0).get("changeno") + "";
			}
		}
		return "1";
	}

}
